package com.cdut.cn.boke.AsyncTask;

import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

@Component
public class MyAsyncTask {

    @Async
    public void doAsync() {
        long startTime = System.currentTimeMillis();
        System.out.println("开始执行异步任务");
        try {
            Thread.sleep(1000); // 毫秒，1秒=1000毫秒
        }catch (Exception e){
            e.printStackTrace();
        }

        long endTime = System.currentTimeMillis();
        long duration = endTime - startTime;
        System.out.println("异步任务执行结束，耗时： " + duration + " 毫秒");
    }

}

